/**
 * Created by zenoniaonline on 14. 4. 8.
 */


var jade = require('jade');
var redis = require("redis");

exports.Test_Redis_Master = redis.createClient(6379, "172.16.3.216");
exports.Real_Redis_Master = redis.createClient(6379, "172.16.1.81");
exports.Test_Redis_Guild_Master = redis.createClient(6379, "172.16.3.216");


exports.Test_showWorldBossRank = function(req, res) {
    var redis = req.app.get('Test_Redis_Master');

    redis.zrevrange('RANK', 0, 200, 'withscores', function (err, members) {

        var fields = ['rank', 'seq', 'score'];
        var rows = [];
        for (var i = 0; i < members.length; i++)
            if (0 != i % 2) {
                var keys = members[i - 1];
                var values = members[i];

                var input = {};
                input[keys] = values;

                rows.push(input);
            }

        res.render('jjaehuny/Test/showWorldBossRank', { type: "TEST SERVER", rows: rows, fields: fields });
    });
};

exports.Test_showGuildRank = function(req, res) {
	
	var redis = req.app.get('Test_Redis_Guild_Master');

    redis.zrevrange('GUILDRANK', 0, 200, 'withscores', function (err, members) {

        var fields = ['rank', 'seq', 'score'];
        var rows = [];
        for (var i = 0; i < members.length; i++)
            if (0 != i % 2) {
                var keys = members[i - 1];
                var values = members[i];

                var input = {};
                input[keys] = values;

                rows.push(input);
            }

        res.render('jjaehuny/Test/showGuildRank', { type: "TEST", rows: rows, fields: fields });
    });
};

exports.Real_showWorldBossRank = function(req, res) {

    var redis = req.app.get('Real_Redis_Master');

    redis.zrevrange('RANK', 0, 200, 'withscores', function(err, members) {
        var fields = ['rank','seq','score'];
        var rows = [];

        for (var i=0;i<members.length;i++)
            if (0 != i % 2)
            {
                var keys = members[i-1];
                var values = members[i];

                var input = {};
                input[keys] = values;

                rows.push(input);

            }

        res.render('jjaehuny/Real/showWorldBossRank', { type:"REAL SERVER",rows: rows, fields: fields });
    });
};

exports.Test_FlushAll = function(req, res) {
    var redis = req.app.get('Test_Redis_Master');
    redis.flushdb( function(err, members) {
        res.render('jjaehuny/Result', { title: 'Express', result:"success" });
    });
};

exports.Test_GuildRank_FlushAll = function(req, res) {
    var redis = req.app.get('Test_Redis_Guild_Master');
    redis.flushdb( function(err, members) {
        res.render('jjaehuny/Result', { title: 'Express', result:"success" });
    });
};

exports.Real_FlushAll = function(req, res) {
    var redis = req.app.get('Real_Redis_Master');
    redis.flushdb( function(err, members) {
        res.render('jjaehuny/Result', { title: 'Express', result:"success" });
    });
};
